<template>
  <div class="header">
    <div class="header-content">
      <img class="logo" src="@/assets/logotext.png" alt="拓诚学院" @click="$router.push('/home')" />
      <div class="header-right">
        <div class="nav-links">
          <span
            v-for="(item, index) in menuList"
            :key="index"
            :class="{ active: currentRoute === item.component }"
            @click="linkPage(item)"
          >{{ item.title }}</span>
        </div>
        <div class="user-info">
          <span class="user-name">{{ userName }}</span>
          <span class="user-icon" @click="handleLogout"></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CommonHeader',
  props: {
    userName: {
      type: String,
      default: ''
    },
    currentRoute: {
      type: String,
      default: 'HomeBanner'
    }
  },
  data() {
    return {
      menuList: [
        {
          title: "首页",
          component: "HomeBanner",
        },
        {
          title: "在线课堂",
          component: "Classroom",
        },
        {
          title: "课堂资源",
          component: "Course",
        },
        {
          title: "直播课程",
          component: "LiveClasses",
        },
        {
          title: "讲师列表",
          component: "ListInstructors",
        },
        {
          title: "学习中心",
          component: "StudyCentre",
        },
      ],
    }
  },
  methods: {
    linkPage(item) {
      this.$emit('component-change', item)
    },
    handleLogout() {
      this.$emit('logout')
    }
  }
}
</script>

<style lang="scss" scoped>
.header {
  background-color: #fff;
  height: 60px;
  width: 100%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  .header-content {
    width: 1200px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .logo {
      width: 152px;
      height: auto;
    }

    .header-right {
      display: flex;
      align-items: center;
      gap: 30px;

      .nav-links {
        display: flex;
        gap: 20px;

        span {
          cursor: pointer;
          padding: 5px 10px;
          font-size: 14px;
          color: #333;
          transition: color 0.3s;

          &:hover {
            color: #409EFF;
          }

          &.active {
            color: #409EFF;
            font-weight: 500;
          }
        }
      }

      .user-info {
        display: flex;
        align-items: center;
        gap: 10px;

        .user-name {
          font-size: 14px;
          color: #333;
        }

        .user-icon {
          width: 32px;
          height: 32px;
          border-radius: 50%;
          background: #eee;
          cursor: pointer;
          // 这里可以添加用户图标的背景图
        }
      }
    }
  }
}
</style> 